package message.mq.producter;

import lodsve.amqp.annotations.EnableAmqp;
import message.pojo.Demo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * .
 *
 * @author sunhao(sunhao.java @ gmail.com)
 * @version V1.0, 2014-9-26 14:38
 */

@EnableAmqp
@Configuration
@Component
public class TestProducter {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Value("${routingKey.first}")
    private String routingKey1;
    @Value("${exchange.first}")
    private String exchange1;

    @Value("${routingKey.second}")
    private String routingKey2;
    @Value("${exchange.second}")
    private String exchange2;

    @Value("${routingKey.third}")
    private String routingKey3;
    @Value("${exchange.third}")
    private String exchange3;

    @Value("${routingKey.fourth}")
    private String routingKey4;
    @Value("${exchange.fourth}")
    private String exchange4;

    public void send1() {
        this.rabbitTemplate.convertAndSend(exchange1, routingKey1, "Hello World!");
        System.out.println("已发送1");
    }

    public void send2(List<Demo> demos) {
        this.rabbitTemplate.convertAndSend(exchange2, routingKey2, demos);
        System.out.println("已发送2");
    }

    public void send3(Demo demo) {
        this.rabbitTemplate.convertAndSend(exchange3, routingKey3, demo);
        System.out.println("已发送3");
    }

    public void send4(Map<String, String> params) {
        this.rabbitTemplate.convertAndSend(exchange4, routingKey4, params);
        System.out.println("已发送4");
    }
}
